import { ZwUnityKitNetwork } from '@zhongwan/zw-unitykit-network';
import { getUrl } from '../utils/index';

/**
 * 获取不同类型的group组
 * @param data
 * @returns
 */
export const groupListApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/tenant/group/getLists'),
        method: 'GET',
        params: data
    });
};

/**
 * 抽奖group组
 * @param data
 * @returns
 */
export const luckDrawGroupListApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/tenant/group/list-for-market'),
        method: 'POST',
        data
    });
};

/**
 * 电商素材group组
 * @param data
 * @returns
 */
export const shopGroupListApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/retail/shop/store-list'),
        method: 'GET',
        params: data
    });
};

/**
 * 获取文本/收集表table
 * @param data
 * @returns
 */
export const textTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/text/list'),
        method: 'POST',
        data
    });
};

/**
 * 获取图片table
 * @param data
 * @returns
 */
export const imageTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/image/list'),
        method: 'POST',
        data
    });
};

/**
 * 获取视频table
 * @param data
 * @returns
 */
export const videoTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/video/list'),
        method: 'POST',
        data
    });
};

/**
 * 获取链接table
 * @param data
 * @returns
 */
export const linkTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/link/list'),
        method: 'POST',
        data
    });
};

/**
 * 获取音频table
 * @param data
 * @returns
 */
export const audioTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/audio/list'),
        method: 'POST',
        data
    });
};

/**
 * 获取文件table
 * @param data
 * @returns
 */
export const fileTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/file/list'),
        method: 'POST',
        data
    });
};

/**
 * 获取抽奖table
 * @param data
 * @returns
 */
export const lotteryTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/market/luckdraw/lottery/list'),
        method: 'GET',
        params: data
    });
};

/**
 * 收集表table
 * @param data
 * @returns
 */
export const collectTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/collect/list'),
        method: 'POST',
        data
    });
};

/**
 * 电商素材-商品素材table
 * @param data
 * @returns
 */
export const productTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/product/list'),
        method: 'POST',
        data
    });
};

/**
 * 电商素材-页面素材table
 * @param data
 * @returns
 */
export const pageTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/page/list'),
        method: 'POST',
        data
    });
};

/**
 * 获取公众号table
 * @param data
 * @returns
 */
export const officialTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/component/offical/article-list'),
        method: 'POST',
        data
    });
};

/**
 * 获取小程序table
 * @param data
 * @returns
 */
export const miniTableApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/content/mini/list'),
        method: 'POST',
        data
    });
};

/**
 * 获取公众号数据
 * @param data
 * @returns
 */
export const officialApi = (app, data?: any) => {
    return ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/component/offical/list'),
        method: 'GET',
        params: data
    });
};

/**
 * 上传文件
 * @param data
 * @returns
 */
export const uploadFileApi = async (app, data?: any) => {
    const res = await ZwUnityKitNetwork({
        url: getUrl(app, '/scrm-api/console/media/file/apply-upload-param'),
        method: 'post',
        data,
        type: 1
    });
    const form = new FormData();
    form.append('key', res.dir);
    form.append('policy', res.policy);
    form.append('OSSAccessKeyId', res.accessid);
    form.append('callback', res.callback);
    form.append('signature', res.signature);
    form.append('expire', res.expire);
    form.append('success_action_status', '200');
    form.append('file', data.file);
    return ZwUnityKitNetwork({
        url: res.host,
        method: 'post',
        type: 2,
        oss: true,
        data: form
    });
};
